<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <!-- 对当前页面的所有带src属性的标签都齐作用-->
    <!-- 动态的获取上下文路径-->
    <base href="<%=request.getContextPath()+"/"%>">

    <title>Title</title>

    <script type="text/javascript" src="js/jquery-3.6.1.js"></script>

    <img src="png/abc.png">

    <script type="text/javascript">
        $(function () {
            // 1.页面加载的时候初始化部门
            $.ajax({
                url: "Dept?action=all",
                type: "GET",
                dataType: "JSON",
                success: function (data) {
                    // 1.找到部门的select
                    var deptEle = $("#deptno");
                    // 2.遍历部门
                    $.each(data, function (index, dept) {
                        // JQuery中如何创建option
                        var option = $(document.createElement("option"));
                        option.text(dept.dname);
                        option.val(dept.deptno);
                        deptEle.append(option);
                    })
                }
            });

            $("#mgr").blur(function () {
                var mgr = $(this).val();
                $.ajax({
                    url: "http://localhost:8080/Emp?action=byName&ename=" + mgr,
                    type: "GET",
                    dataType: "JSON",
                    success: function (data) {
                        if (!data) {
                            alert("【" + name + "】不存在");
                            return;
                        }
                        $("#mgr").val(data.empno);
                    }
                });
            });

        })
    </script>

</head>
<body>
<h3>添加员工</h3>


<form method="post" action="http://localhost:8080/Emp?action=add">
    <table border="1">
        <tr>
            <td> 姓名:</td>
            <td>
                <input type="text" name="ename" value="toString">
            </td>
        </tr>

        <tr>
            <td> 职位:</td>
            <td>
                <input type="text" name="job" value="Java开发工程师">
            </td>
        </tr>

        <tr>
            <td> 工资:</td>
            <td>
                <input type="text" name="sal" value="13000">
            </td>
        </tr>

        <tr>
            <td> 奖金:</td>
            <td>
                <input type="text" name="comm" value="5000.0">
            </td>
        </tr>

        <tr>
            <td> 入职时间:</td>
            <td>
                <input type="date" name="hiredate" value="2022-09-05">
            </td>
        </tr>

        <tr>
            <td> 部门:</td>
            <td>
                <select name="deptno" id="deptno">
                </select>
            </td>
        </tr>

        <tr>
            <td> 领导:</td>
            <td>
                <input type="text" name="mgr" id="mgr" value="7369">
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="submit" value="添加">
                <input type="reset" value="重置">
            </td>
        </tr>
    </table>
</form>
</body>
</html>
